# file reads the cleanStockData.RData file and outputs
# the list of symbols in a series of latex tables

library(xtable)

# create new environment to avoid cluttering the current environment with 2040 symbols
env <- new.env()
load("/home//voellenk/stratlab_workdir//cleanData/cleanStockData_2000_2014_quantiles.RData", envir=env)

assign("syms", get("syms", envir=env))
syms.c <- syms[,c(1,2,4,10,11,15,16)]
syms.c$MarketCap <- format(syms$MarketCap, digits=3)
syms.c$median.ret <- syms.c$median.ret * 100
syms.c$sd.ret <- syms.c$sd.ret * 100
syms.c$fac <- as.factor(paste0(syms.c$sd.q, syms.c$median.q))
syms.c <- syms.c[with(syms.c, order(-median.ret)),]

groups <- split(syms.c, syms.c$fac)

for (i in names(groups)) {
  caption <- paste("Gruppe", i)
  tbl <- xtable(groups[[i]][,c(1:5)], caption=caption)
  print(tbl, size="tiny", include.rownames=FALSE,
        file="groups.tex", append=TRUE)
}
